package com.lwj.liwanjia.utils;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lwj.liwanjia.R;

/**
 * Created by Administrator on 2017/9/17.
 */

public class KuaiDiPayDialog extends Dialog implements View.OnClickListener {
    private Context context;
    private String price;//总价格
    private RelativeLayout payYikatong;
    private TextView tvYikatong;
    private TextView tvZhifubao;
    private TextView tvWeixin;
    private RelativeLayout payZhifubao;
    private RelativeLayout payWeixin;
    private ImageView ivQuxiao, ivYikatong, ivZhifubao, ivWeixin;
    private TextView tvPay;//确认付款
    private int checkPosition = 0;

    public KuaiDiPayDialog(Context context, String tvPrice) {
        super(context, R.style.MyDialog);
        this.context = context;
        this.price = tvPrice;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.kuaidi_dialog);
        initView();
        initClick();
    }

    private void initClick() {
        payYikatong.setOnClickListener(this);
        payWeixin.setOnClickListener(this);
        payZhifubao.setOnClickListener(this);
        ivQuxiao.setOnClickListener(this);
    }

    private void initView() {
        Window window = getWindow();
        window.setGravity(Gravity.BOTTOM);
        WindowManager.LayoutParams params = window.getAttributes();
        setCanceledOnTouchOutside(false);
        params.width = params.MATCH_PARENT;
        params.height = params.WRAP_CONTENT;
        window.setAttributes(params);
        ivQuxiao = (ImageView) findViewById(R.id.iv_quxiao);
        ivYikatong = (ImageView) findViewById(R.id.iv_yikatong);
        ivZhifubao = (ImageView) findViewById(R.id.iv_zhifubao);
        ivWeixin = (ImageView) findViewById(R.id.iv_weixin);
        TextView tvPrice = (TextView) findViewById(R.id.tv_price);
        tvPrice.setText(price + "元");
        payYikatong = (RelativeLayout) findViewById(R.id.pay_yikatong);
        tvYikatong = (TextView) findViewById(R.id.tv_yikatong);
        tvYikatong.setText("￥" + price + "元");
        tvZhifubao = (TextView) findViewById(R.id.tv_zhifubao);
        tvPay = (TextView) findViewById(R.id.tv_pay);
        tvWeixin = (TextView) findViewById(R.id.tv_weixin);
        payZhifubao = (RelativeLayout) findViewById(R.id.pay_zhifubao);
        payWeixin = (RelativeLayout) findViewById(R.id.pay_weixin);
    }

    public int getCheckPosition() {
        return checkPosition;
    }

    public TextView getPay() {
        return tvPay;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.pay_weixin://微信支付：
                checkPosition = 2;
                ivWeixin.setImageResource(R.mipmap.zhifu);
                ivZhifubao.setImageResource(R.mipmap.zhifu_1);
                ivYikatong.setImageResource(R.mipmap.zhifu_1);
                tvWeixin.setText("￥" + price + "元");
                tvWeixin.setVisibility(View.VISIBLE);
                tvZhifubao.setVisibility(View.GONE);
                tvYikatong.setVisibility(View.GONE);
                break;
            case R.id.pay_yikatong://一卡通支付
                checkPosition = 0;
                ivWeixin.setImageResource(R.mipmap.zhifu_1);
                ivZhifubao.setImageResource(R.mipmap.zhifu_1);
                ivYikatong.setImageResource(R.mipmap.zhifu);
                tvYikatong.setText("￥" + price + "元");
                tvWeixin.setVisibility(View.GONE);
                tvZhifubao.setVisibility(View.GONE);
                tvYikatong.setVisibility(View.VISIBLE);
                break;
            case R.id.pay_zhifubao://支付宝支付
                checkPosition = 1;
                ivWeixin.setImageResource(R.mipmap.zhifu_1);
                ivZhifubao.setImageResource(R.mipmap.zhifu);
                ivYikatong.setImageResource(R.mipmap.zhifu_1);
                tvZhifubao.setText("￥" + price + "元");
                tvWeixin.setVisibility(View.GONE);
                tvZhifubao.setVisibility(View.VISIBLE);
                tvYikatong.setVisibility(View.GONE);
                break;
            case R.id.iv_quxiao://取消支付
                dismiss();
                break;
        }
    }
}
